from typing import Type

import reflex as rx

from base.state import StateBase


class Alert:
    """ 警告提示 """

    @staticmethod
    def alert(
        state_cls: Type[StateBase],
        title: str,
    ):
        return rx.alert_dialog.root(
            rx.alert_dialog.trigger(
                rx.button(title),
            ),
            rx.alert_dialog.content(
                rx.alert_dialog.title(title),
                rx.flex(
                    rx.alert_dialog.cancel(
                        rx.button("OK", on_click=state_cls.close_alert),
                    ),
                    spacing="3",
                ),
            ),
            open=state_cls.alert_opened,
        )
